package main

import (
	LogUtils "IMServices/LogService"
	"IMServices/LoginService/ClientLoginOrder"
	"IMServices/LoginService/LoginOrder"
	"IMServices/NetIO/ClientNetIO"
	ServiceNetIO2 "IMServices/NetIO/ServiceNetIO"
	"IMServices/SqlUtils/MysqlUtils"
	"IMServices/SqlUtils/RedisManager"
)

func handleFunc(msg chan ServiceNetIO2.RequestBuffer, finish chan bool) {
	for {
		select {
		case data := <-msg:
			//启动业务函数go程
			go LoginOrder.Test(data)
		case <-finish:
			return
		}
	}

}

func sendTest() {
	// 测试发送 gRPC 请求
	//req := &ServiceNetIO2.NewMessageRequest{OrderId: 1}
	//res, err := server.StatusServer.Client.NewNotify(server.StatusServer.Ctx, req)
	//if err != nil {
	//	log.Fatalf("failed to call YourMethod: %v", err)
	//}
	//log.Printf("response: %v", res)
}

//func release() {
//	releaseNet()
//	releaseLog()
//	releaseMysql()
//	releaseRedis()
//	releaseMongodb()
//}

func main() {
	//方法注册
	ClientLoginOrder.Init()

	addr := "localhost:11111"
	//开始监听，并且打开go程函数
	LoginOrder.Server.Listen.StartServiceNet(addr, handleFunc, 1000)

	LoginOrder.Server.Connect("StatusServer", []string{"localhost:12222"})

	//LoginOrder.Server.Connect("MessageServer", []string{"localhost:13333"})

	tcpServer := &ClientNetIO.TcpServer{}
	//开启客户端监听
	tcpServer.StartListen("127.0.0.1:33781")

	//go server.MessageServer.Connect([]string{"localhost:13333"})

	mysqlClient := MysqlUtils.MysqlClient{}
	//Mysql连接池启动
	err := mysqlClient.StartMysqlService("127.0.0.1", "3306", "root", "123456", "imservices")
	if err != nil {
		LogUtils.LogError(err.Error())
	}

	redis := RedisManager.RedisClient{}

	err = redis.StartRedisService("127.0.0.1:6379", "", 0, 3, 100)
	if err != nil {
		LogUtils.LogError(err.Error())
	}
	select {}
}
